// directives/clickOutside.js
import { onMounted, onUnmounted } from 'vue';

const clickOutside = {
    mounted(el, binding) {
        const handleClick = (event) => {
            if (!(el === event.target || el.contains(event.target))) {
                binding.value(event);
            }
        };
        // 直接在mounted钩子函数内注册事件监听器
        document.addEventListener('click', handleClick);
        // 返回一个卸载函数，在指令解绑时调用
        return () => {
            document.removeEventListener('click', handleClick);
        };
    }
};

export default clickOutside;